package com.xtianzhuang.www.study2019.kafka;


import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

public class KafkaProducerTest {



	public static void getConsumer(String targetTopic,
			String targetServerIp) throws IOException {
		Map<String, Object> props = new HashMap<String, Object>();
		props.put("enable.auto.commit", "true");
		props.put("auto.offset.reset", "earliest");
		props.put("auto.commit.interval.ms", "1000");
		props.put("group.id", "test20190821test");
		props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
		props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
		String[] topics = new String[]{targetTopic};
		props.put("bootstrap.servers", targetServerIp);
		Producer<String, String> producer = new KafkaProducer(props);
		producer.send(new ProducerRecord<String, String>("CRM_CUE.UCR_CEN.TD_B_DISCNT_ITEM", "20190823test"));

		producer.close();
		System.out.println("完成");

	}


	public static void main(String[] args) throws IOException {
		KafkaProducerTest.getConsumer(
				"CRM_CUE.UCR_CEN.TD_B_DISCNT_ITEM",
				"10.161.11.186:6667,10.161.11.187:6667,10.161.11.188:6667,10.161.11.189:6667,10.161.11.190:6667,10.161.11.191:6667,10.161.11.192:6667,10.161.11.193:6667,10.161.11.194:6667,10.161.11.195:6667");
	}
}
